def IP(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True

n=int(input())



n1=n//1000
n2=(n//100)%10
n3=(n//10)%10
n4=n%10

MP=0

if IP(n1) and MP<n1: MP=n1
if IP(n2) and MP<n1: MP=n2
if IP(n3) and MP<n1: MP=n3
if IP(n4) and MP<n1: MP=n4

n12=n1*10+n2
if IP(n12) and MP<n12: MP=n12
n13=n1*10+n3
if IP(n13) and MP<n13: MP=n13
n14=n1*10+n4
if IP(n14) and MP<n14: MP=n14
n23=n2*10+n3
if IP(n23) and MP<n23: MP=n23
n24=n2*10+n4
if IP(n24) and MP<n24: MP=n24
n34=n3*10+n4
if IP(n34) and MP<n34: MP=n34

n123=n1*100+n2*10+n3
if IP(n123) and MP<n123: MP=n123
n124=n1*100+n2*10+n4
if IP(n124) and MP<n124: MP=n124
n134=n1*100+n3*10+n4
if IP(n134) and MP<n134: MP=n134
n234=n2*100+n3*10+n4
if IP(n234) and MP<n234: MP=n234

if IP(n) and MP<n: MP=n

if n<10000 and n>999:
    print(MP)
else:
    print('0')
